package com.jie.myvhr.service;

import com.jie.myvhr.bean.Position;
import com.jie.myvhr.mapper.EmpMapper;
import com.jie.myvhr.mapper.PositionMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jie
 * @date 2019/6/30 -16:42
 */
@Service
public class PositionService {
    @Resource
    private PositionMapper positionMapper;
    @Resource
    private EmpMapper empMapper;

    public List<Position> getAllPos() {
        return positionMapper.getAllPos();
    }

    public int updatePosById(Position position) {
        return positionMapper.updatePosById(position);
    }
    public int deletePosById(String pids) {
        String[] split = pids.split(",");
        int countByPosId = empMapper.getCountByPosId(split);
        if (countByPosId>0) {
            return -1;
        }else {
            if (positionMapper.deletePosById(split) == split.length){
                return 1;
            }
        }
        return 0;
    }
    public int addPos(Position pos) {
        if (positionMapper.getPosByName(pos.getName()) != null) {
            return -1;
        }
        return positionMapper.addPos(pos);
    }
}
